﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Editor;
using Microsoft.VisualStudio.Text.Formatting;


namespace BasicallyNot.CodeTransformers.Handlers
{

	internal class BeginBlock : IVisualHandler
	{

		void IVisualHandler.Handle( VisualHandlerEventArg arg )
		{
			SnapshotSpan span = new SnapshotSpan( arg.Manager.View.TextSnapshot, Span.FromBounds( arg.Line.Start, arg.Line.End ) );
			Geometry g = arg.Manager.View.TextViewLines.GetMarkerGeometry( span );

			if ( g != null ) {
				TextBlock curlyBracket = new TextBlock();
				curlyBracket.Text = "{";
				curlyBracket.Foreground = arg.CurlyBracketForeground;
				curlyBracket.FontFamily = arg.Manager.FontFamily;
				curlyBracket.FontSize = arg.Manager.FontSize;

				// align the text with the top of the bounds of the text geometry
				Canvas.SetLeft( curlyBracket, g.Bounds.Right + 10 );
				Canvas.SetTop( curlyBracket, g.Bounds.Top + 2 );

				arg.Manager.Layer.AddAdornment( AdornmentPositioningBehavior.TextRelative, span, null, curlyBracket, null );
			}
		}

	}

}
